package de.koller.aframe.util.misc;

public class ABoundingBox {
	
	public float x, y, w, h;

	public ABoundingBox() {
		this( 0, 0, 0, 0 );
	}

	public ABoundingBox( float x, float y, float w, float h ) {
		this.x = x;
		this.y = y;
		this.w = w;
		this.h = h;
	}
	
	public ABoundingBox( ABoundingBox o ) {
		this( o.x, o.y, o.w, o.h );
	}
	
	public void set( float x, float y, float w, float h ) {
		this.x = x;
		this.y = y;
		this.w = w;
		this.h = h;
	}
	
	public boolean isInBound( float x, float y ) {
		if( x < this.x ) return false;
		if( y < this.y ) return false;
		if( x > this.x + this.w ) return false;
		if( y > this.y + this.h ) return false;
		
		return true;
	}

	@Override
	public int hashCode() {
		int hash = 7;
		hash = 47 * hash + Float.floatToIntBits( this.x );
		hash = 47 * hash + Float.floatToIntBits( this.y );
		hash = 47 * hash + Float.floatToIntBits( this.w );
		hash = 47 * hash + Float.floatToIntBits( this.h );
		return hash;
	}

	@Override
	public boolean equals( Object obj ) {
		if( obj == null ) {
			return false;
		}
		if( getClass() != obj.getClass() ) {
			return false;
		}
		final ABoundingBox other = ( ABoundingBox ) obj;
		if( Float.floatToIntBits( this.x ) != Float.floatToIntBits( other.x ) ) {
			return false;
		}
		if( Float.floatToIntBits( this.y ) != Float.floatToIntBits( other.y ) ) {
			return false;
		}
		if( Float.floatToIntBits( this.w ) != Float.floatToIntBits( other.w ) ) {
			return false;
		}
		if( Float.floatToIntBits( this.h ) != Float.floatToIntBits( other.h ) ) {
			return false;
		}
		return true;
	}

	@Override
	public String toString() {
		return "ABoundingBox{" + "x=" + x + ", y=" + y + ", w=" + w + ", h=" + h + '}';
	}
	
}
